using System;
using Glue;
using Xunit;

namespace GlueTests.MapperTests
{
    public class When_mapping_property_of_same_type
    {
        private readonly string theName;
        private readonly Mapping<DomainPerson, GuiPerson> mapping;
        private DomainPerson domainPerson;
        private GuiPerson guiPerson;

        public class GuiPerson
        {
            public String FirstName { get; set; }
        }

        public class DomainPerson
        {
            public String GivenName { get; set; }
        }

        public When_mapping_property_of_same_type()
        {
            theName = "Tore";
            domainPerson = new DomainPerson();
            guiPerson = new GuiPerson();
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(master => master.GivenName, t => t.FirstName);
        }

        [Fact]
        public void Should_map_relation_towards_right()
        {
            domainPerson.GivenName = theName;
            mapping.Map(domainPerson,  guiPerson);
            Assert.Equal(theName, guiPerson.FirstName);
        }

        [Fact]
        public void Should_map_relation_towards_left()
        {
            guiPerson.FirstName = theName;
            mapping.Map(guiPerson,  domainPerson);
            Assert.Equal(theName, domainPerson.GivenName);
        }
    }
}